package com.wang.common.result;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wjh
 * @create 2023-04-17
 */
@Data
public class Result<T> implements Serializable {

//    @ApiModelProperty("编码：200成功，0和其他数字为失败")
    private Integer code;

//    @ApiModelProperty("返回信息")
    private String message;

//    @ApiModelProperty("数据")
    private T data;

//    @ApiModelProperty("动态数据")
    private Map map = new HashMap();

    public static <T> Result<T> success(T object){
        Result<T> r = new Result<>();
        r.data = object;
        r.code = 200;
        return r;
    }
    public static Result success(){
        Result r = new Result();
        r.data = null;
        r.code = 200;
        return r;
    }

    public static <T> Result<T> error(String msg){
        Result r = new Result();
        r.message = msg;
        r.code = 0;
        return r;
    }

    public static <T> Result<T> error(Integer code, String msg){
        Result r = new Result();
        r.message = msg;
        r.setCode(code);
        return r;
    }
    public static <T> Result<T> success(T object,String msg){
        Result<T> r = new Result<>();
        r.data = object;
        r.message = msg;
        r.code = 200;
        return r;
    }
}
